package com.ptsolusi.ceriacrudwicket.tool.pages.windows;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;

import com.ptsolusi.ceriacrudwicket.logic.CustomerLogic;
import com.ptsolusi.ceriacrudwicket.model.Customer;
import com.ptsolusi.ceriacrudwicket.tool.Locator;

public class DeleteCustomer extends Panel {
	
	private static final long serialVersionUID = 1L;

	public DeleteCustomer(String id, final ModalWindow window, final Customer customer) {
		super(id);
		
		window.setTitle("Delete Customer");
		window.setInitialHeight(150);
		window.setInitialWidth(350);
		
		Form form = new Form("form");
		
		Label lblCustomer = new Label("lblCustomer", customer.getFirstName());
		form.add(lblCustomer);
		
		AjaxFallbackButton btnYes = new AjaxFallbackButton("btn_yes", form) {
			
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form form) {
				getCustomerLogic().deleteCustomer(customer);
				window.close(target);
			}
			
			
		};
		
		form.add(btnYes);
		
		AjaxFallbackButton btnNo = new AjaxFallbackButton("btn_no", form){
			
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form form) {
				// TODO Auto-generated method stub
				window.close(target);
			}
		};
		form.add(btnNo);
		btnNo.setDefaultFormProcessing(true);
		add(form);
	}
	
	
	protected CustomerLogic getCustomerLogic(){
		return Locator.getCustomerLogic();
	}

}
